var APPLICATION_SERVER_PATH=".";

function UrlTransition(URL){
	window.location.href=URL;
}


function Ajax()
{
	this.ajax=null;
	try{
		this.ajax=new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			this.ajax=new ActiveXObject("Microsoft.XMLHTTP"); 
		}catch(e){
			this.ajax=null;
		}
	}
	
	if (this.ajax==null && typeof XMLHttpRequest!='undefined') {
  		this.ajax = new XMLHttpRequest();
	}
	this.params=new Array();
};

var _aj = Ajax.prototype;

//设置请求url
_aj.setServer = function (server){
	this.server=server;
};

//请求参数，没有就不要调用
_aj.setParam = function (name,value){
	var obj = new Array();
	obj[0]=name;
	//obj[1]=encodeURIComponent(value);
	obj[1]=(value);
	this.params.push(obj);
};

//post方式的参数
_aj.getPostString = function (){
	var str = "";
	for(var i=0;i<this.params.length;i++){
		var param = this.params[i];
		str+=param[0]+"="+param[1];
		if(i!=this.params.length-1){
			str+="&";
		}
	}
	return str;
};

//get方式的参数
_aj.getGetString = function (){
	var str = this.getPostString();
	if(str.length>0){
		return this.server+"?"+str;
	}else{
		return this.server;
	}
};

//以get方式发送请求
_aj.sendByGet = function (returnType,asyn){
	this.returnType = returnType;
	var req = this.getGetString();
	this.ajax.open("GET",req,asyn);
	if(asyn){
		this.ajax.onreadystatechange = this.stateChange.bind(this);
	}
	try{
		this.ajax.send(null);
	}catch(e){
		alert("与服务器连接失败");
	}
};

_aj.setCallback = function (cb){
	this.cb=cb;
}
//以post方式发送请求
_aj.sendByPost = function (returnType,asyn){
	this.returnType = returnType;
	var req = this.server;
	var param = this.getPostString();
	alert(param);
	this.ajax.open("POST",req,asyn);
	this.ajax.setRequestHeader("content-length",param.length); 
	this.ajax.setRequestHeader("content-type","application/x-www-form-urlencoded");
	if(asyn){
		//.bind为function.js提供
		this.ajax.onreadystatechange = this.stateChange.bind(this);
	}
	try{
		this.ajax.send(param);
	}catch(e){
		alert("与服务器连接失败");
	}
};

//异步调用
_aj.stateChange = function (){
	var state = this.ajax.readyState;
	if(state==4){
		var rType = this.returnType;
		//0：返回ajax.responseText
		//1：返回ajax.responseXML
		if(rType==0){
			if(this.cb!=null)
				this.cb(this.ajax.responseText);
		}else if(rType==1){
			if(this.cb!=null)
				this.cb(this.ajax.responseXML);
		}
	}	
};


function getValueByUrl(objectName) {
    var url = window.location.href;
    var retval = "";
    var tmp = url.indexOf("?");
    if (tmp >= 0) {
        var allObject = url.substring(tmp + 1, url.length);
        var objectArr = allObject.split("&");
        for (var i = 0; i < objectArr.length; i++) {
            tmp = objectArr[i].indexOf("=");
            if (objectName == objectArr[i].substring(0, tmp)) {
                retval = objectArr[i].substring(tmp + 1, objectArr[i].length);
                break;
            }
        }
    }
    return retval;
}

function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    if (arguments.length == 1) 
      return element;
    elements.push(element);
  }
  return elements;
};

function ElementData(element,subNodeName){
	var d=element.getElementsByTagName(subNodeName)[0].firstChild.data;
	return d;
};

function $C(tag){
	var obj=document.createElement(tag);
	return obj;
};

var $A = Array.from = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
};

Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
};

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
};

function getRequest(){
	var req=null;
			try{
				req=new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					req=new ActiveXObject("Microsoft.XMLHTTP"); 
				}catch(e){
					req=null;
				};
			};
			if (req==null && typeof XMLHttpRequest!='undefined') {
	  			req = new XMLHttpRequest();
			};
			return req;
};
